package day21;
class Solution {
    public static void main(String[] args) {
        addBinary("1", "111");
    }
    public static String addBinary(String a, String b) {
        //思路：转化为整数，相加减后转化为字符串
        if(a.length()==1&&a.charAt(0)=='0'){
            return b;
        }
        if(b.length()==1&&b.charAt(0)=='0'){
            return a;
        }
        int num1=0;
        int num2=0;
        for(int i=a.length()-1;i>=0;--i){
            if(a.charAt(i)=='1')
                num1+=Math.pow(2,a.length()-1-i);
        }
        for(int i=b.length()-1;i>=0;--i){
            if(b.charAt(i)=='1')
                num2+=Math.pow(2,a.length()-1-i);
        }
        int res=num1+num2;
        StringBuilder sb=new StringBuilder();
        while(res>0){
            sb.append(res%2);
            res/=2;
        }
        sb.reverse();
        return sb.toString();

    }
}